# -*- coding: utf-8 -*-


from itertools import product
import threading
import unittest
import sys
import os
import time
import warnings

# 添加执行环境
file_exec_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.insert(0, file_exec_path)
from framework_strategy.gopy.trader.engine import EmailEngine, MainEngine, EventEngine  # NOQA
from framework_strategy.gopy.base.api import API, Event  # NOQA
from framework_strategy.gopy.gateways.object import *  # NOQA
from framework_strategy.gopy.gateways.xt.xt_api import XTGateway  # NOQA
from framework_strategy.manager import *  # NOQA
from framework_strategy.gopy.core.actor import *  # NOQA


def product(actor):
    while 1:
        actor.send(2)

def consumer(actor):
    while 1:
        res = actor.get()
        print("[res] :", res)
    pass

class ActorTest(unittest.TestCase):

    def test_init(self):

        actor = Actor()
        tasks = []

        for _ in range(10):
            t1 = threading.Thread(target=product, args=(actor,), daemon=True)
            t2 = threading.Thread(target=product, args=(actor,), daemon=True)
            t3 = threading.Thread(target=consumer, args=(actor,), daemon=True)
            tasks.append(t1)
            tasks.append(t2)
            tasks.append(t3)

        for t in tasks:
            t.start()

        while 1:
            time.sleep(1)
        pass

if __name__ == "__main__":
    unittest.main()
    pass


